<?php

class notice extends CActiveRecord
{
	/**
	 * The followings are the available columns in table 'notice':
	 * @var integer $id
	 * @var integer $level
	 * @var string $title
	 * @var string $desc
	 * @var integer $date
	 * @var integer $table_id
	 * @var integer $table_ref
	 */
         //Table const value
         CONST Contact=1;
         // Alert const value
         CONST LOW=1,MEDIUM=2,HIGH=3,VHIGH=4,WARNING=5;
	/**
	 * Returns the static model of the specified AR class.
	 * @return CActiveRecord the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'notice';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		return array(
			array('title','length','max'=>50),
			array('level, title, desc, date', 'required'),
			array('level, date, table_id, table_ref', 'numerical', 'integerOnly'=>true),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'Id',
			'level' => 'Level',
			'title' => 'Title',
			'desc' => 'Desc',
			'date' => 'Date',
			'table_id' => 'Table',
			'table_ref' => 'Table Ref',
		);
	}
        // Standard process
        public function NewNotice($title, $desc, $lvl=1, $table_id=0, $table_ref=0, $date=0) {
            $this->date = $date==0?date():$date;
            $this->level = $lvl;
            $this->title = $title;
            $this->desc = $desc;
            $this->table_id = $table_id;
            $this->table_ref = $table_ref;
            return $this->save();
        }
}